package zust.se.ssm.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import zust.se.ssm.mapper.ContactsMapper;
import zust.se.ssm.model.Contacts;
import zust.se.ssm.service.ContactsServiceI;

import javax.annotation.Resource;
import java.util.List;

/**
 * 
 * @author czg
 * @since 2022/12/14 15:26
 */
@Service
@Transactional
public class ContactsServiceImpl implements ContactsServiceI {
//    在service中注入dao/mapper的接口
//    注入dao/mapper的时候用@Resouce
    @Resource
    ContactsMapper contactsMapper;
    @Override
    public Contacts getById(int id) {
        return contactsMapper.getById(id);
    }

    @Override
    public List<Contacts> getAll() {
        return contactsMapper.allContacts();
    }

    @Override
    public List<Contacts> searchByName(String name) {
        return contactsMapper.searchByName(name);
    }
    @Override
    public List<Contacts> searchByName(String name,int userId) {
        return contactsMapper.searchByUserIDAndName(name,userId);
    }

    @Override
    public void updateContacts(Contacts contacts) {
        contactsMapper.updateContacts(contacts);
    }

    @Override
    public void delContacts(int id) {
        contactsMapper.deleteById(id);
    }

    @Override
    public void addContacts(Contacts contacts) {
        contactsMapper.add(contacts);
    }

    @Override
    public List<Contacts> getUserContacts(int id) {
        return contactsMapper.getUserContacts(id);
    }
}
